package cn.cdutetc.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet(name = "/def",value = "")
public class RegisterServlet  extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        String che = req.getParameter("hobby");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("username");
        String pwd = req.getParameter("password");
        String che = req.getParameter("hobby");
        //访问数据库，从user表中读取数据，满足条件
        //select count(*) from user where name = username and password = pwd;
        //否则则收是合法用户
        //重定向,地址栏会变为定向的地址，重定向实际上
        HttpSession session = req.getSession(true);
        session.setAttribute("user",username);
        //转向,地址栏不会发声，转向是一次req请求，也就意味着转向他的req对象里的属性在他所转向的页面
        //
        req.getRequestDispatcher("/index.jsp").forward();

    }
}
